//
//  JSLBillLoanCell.m
//  JingleSpeedLoan
//
//  Created by 宋志彬 on 2018/8/3.
//  Copyright © 2018年 宋质彬. All rights reserved.
//

#import "JSLBillLoanCell.h"

@interface JSLBillLoanCell ()
@property (nonatomic , weak) UIView *colorView;
@property (nonatomic , weak) UILabel *nameLab;
@property (nonatomic , strong) NSArray *textArray;

@end

@implementation JSLBillLoanCell

#pragma mark - init
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        
        [self setUpAllChildView];
        
    }
    return self;
}
- (void)setInfo:(NSDictionary *)info {
    _info = info;
//    @"name":@"百度有钱花",
//    @"money":@"3000",
//    @"moneylixi":@"0.02",
//    @"loanTime":@"2018-05-22",
//    @"repaymentTime":@"2018-06-22",
    
    
    CGFloat lixiValue = [info[@"moneylixi"] floatValue]*0.01 *[info[@"loanTime"] integerValue]*[info[@"money"] floatValue];
    
    CGFloat totleValue = lixiValue +[info[@"money"] floatValue];
    
    self.nameLab.text = info[@"name"];
    self.textArray = @[info[@"money"],[NSString stringWithFormat:@"%.2f",lixiValue],[NSString stringWithFormat:@"%.2f",totleValue]];
}
#pragma mark - 配置视图
- (void)layoutSubviews{
    [super layoutSubviews];
    [self configFrame];
}

- (void)configFrame{
    self.colorView.frame = CGRectMake(10 *AutoSizeScaleXX, 15*AutoSizeScaleYY, 4*AutoSizeScaleXX, 13*AutoSizeScaleYY);
    
    
    CGSize nameSize = [self.nameLab.text sizeWithAttributes:@{NSFontAttributeName : self.nameLab.font}];
    self.nameLab.frame = CGRectMake(self.colorView.right +10*AutoSizeScaleXX, 14.5*AutoSizeScaleYY, nameSize.width, nameSize.height);
    
    self.nameLab.centerY = self.colorView.centerY;
    
    for (NSInteger i = 0; i < self.textArray.count; i ++) {
        UILabel *textLab = [self.contentView viewWithTag:100 +i];
        textLab.frame = CGRectMake(0 +(self.contentView.width/3)*i, self.nameLab.bottom+10*AutoSizeScaleYY, self.contentView.width/3, 20);
        
        textLab.text = self.textArray[i];
        
        UILabel *contenLab = [self.contentView viewWithTag:1000 +i];
        contenLab.frame = CGRectMake(0 +(self.contentView.width/3)*i, textLab.bottom+2*AutoSizeScaleXX, self.contentView.width/3, 20);
        
        
    }

}
- (void)setUpAllChildView{
    self.colorView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:[@"#338cff" hexStringToColor] superView:self.contentView];
    
    self.nameLab = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:@"" font:MEDIUM_FONT(14) textColor:[@"#333333" hexStringToColor] textAlignment:NSTextAlignmentLeft SuperView:self.contentView];
    
    NSArray *textArray = @[@"账单金额(元)",@"利息(元)",@"应还总金额(元)"];
    NSArray *contentArray = @[@"--",@"--",@"--"];
    for (NSInteger i = 0; i <3 ; i ++) {
        UILabel *textlab =  [JSLKitFactory jsl_labelWithFrame:CGRectZero text:contentArray[i] font:REGULAR_FONT(16) textColor:[@"#666666" hexStringToColor] textAlignment:NSTextAlignmentCenter SuperView:self.contentView];
        textlab.tag = i +100;
        
        UILabel *contenLab = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:textArray[i] font:REGULAR_FONT(10) textColor:[@"#999999" hexStringToColor] textAlignment:NSTextAlignmentCenter SuperView:self.contentView];
        contenLab.tag = i +1000;
    }
}

#pragma mark - 创建cell
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * ID = @"JSLBillLoanCell";
    id cell = [tableView dequeueReusableCellWithIdentifier:ID ];
    
    if (cell == nil) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    
    return cell;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


@end
